<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/component/commonTagLib.jsp" %>

<!DOCTYPE html>
<html>
<head>
	<title>区域配送企业数</title>
	<%@ include file="/WEB-INF/component/commonCSS.jsp"%>
	<style type="text/css">
    .box-body{
    margin-top:-2px;
    }    	
    </style>
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
    <section class="content-header">
        <h1>区域配送企业数</h1>
        <ol class="breadcrumb">
            <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i>首页</a></li>
            <li class="active"><a href="#">交易</a></li>
            <li class="active"><a href="#">采购规则查询</a></li>
            <li class="active"><a href="#">区域配送企业数</a></li>
        </ol>
    </section>
    <section class="content">
       <form id="form" method="post" class="form-horizontal">
        <div class=" box box-success">
            <div class="box-body">
				<div class="input">
					<div class="textalign1" >地区名称：</div>
                    <div class="boxinput"> 
                        <input type="text" class="textinput" id="areaName" placeholder="地区名称"/>     
                    </div>
                    <div class="textalign1" >地区编码：</div>
                    <div class="boxinput"> 
                       <input type="text" class="textinput" id="areaCode" placeholder="地区编码"/>     
                    </div>
                    
                   ${list==null?"<!--":"" } 
                   <div class="textalign1">上级地区：</div>
                    <div class="boxinput">
                        <select class="textinput" id="fatherCode">
							 <option value="">请选择</option>
							 <c:forEach items="${list}" var="area">
							 	<option value="${area.area_id}">${area.area_name}</option>
							 </c:forEach>
                        </select>
                    </div> 
                     ${list==null?"-->":"" }
                    <div class="textalign1" >
                             <button type="button" class="btn btn-success btn-sm" onclick="search()" id="selectc">查&nbsp;询</button>
                         </div> 
                </div>                
           </div>
        </div>
        </form>
        <table class="jqgrid" id="gridlist"></table>
        <div id="gridpage"></div>
    </section>
   <%@ include file="/WEB-INF/component/commonJS.jsp"%>
    <script type="text/javascript">
    
    //绑定回车
    $('#areaCode,#areaName,#fatherCode').bind('keydown', function(event) {
        if (event.keyCode == "13") {        //13 位电脑上回车键的位置代码
            $('#selectc').click();
        }
    }); 
    
    $("#areaCode").focus();//加载页面光标在第一个查询框上
    
    function search(currentPage) {
        var areaCode = $.trim( $("#areaCode").val());
        var areaName = $.trim( $("#areaName").val());
        var fatherCode = $.trim( $("#fatherCode").val()) || "";
        $("#gridlist").jqGrid('setGridParam',{  
            datatype:'json',
            postData:{"areaCode":areaCode, "areaName":areaName,"fatherCode":fatherCode},
            page:currentPage||1
        }).trigger("reloadGrid"); //重新载入  
    }
    
    $(function () {
        $("#gridlist").jqGrid({
            url: "getSetupAreaDelDataList.html",
            mtype: "post",
            datatype: "json",
            postData: {"projId" : "${projId}"},
            autowidth: true,
          //  height: 358,
            colNames: [
                '地区编码', 
                '地区名称',
                '地区全称',
                '基层医疗机构配送数',
                '县级及县以上医疗机构配送数'
            ],
            colModel: [
                { name: 'area_id', width: 10, align:"center", sortable: false},
                { name: 'area_name', width: 15, align:"center", sortable: false },
                { name: 'ar_fullname', width: 10, align:"center", sortable: false},
                { name: 'max_delnum_base', width: 10, align:"center", sortable: false},
                { name: 'max_delnum_county', width: 10, align:"center", sortable: false}
            ], 
            rowNum: 20,
            rowList: [10, 20, 50, 100],
            rownumbers: true,
            pager: "#gridpage",
            viewrecords: true,
            caption: "区域配送企业数列表",
            jsonReader: {
            	id: "area_id"
            }
        });
        
        $("#gridlist").jqGrid('navGrid', '#gridpage', { add: false, edit: false, del: false, search: false, refresh: false });
        $(window).trigger("resize");
		$("#gridlist").jqGrid("setGridHeight",create());
        $("#area2").HNSelect({
        	parent_selector: "#area1",  url: "${pageContext.request.contextPath}/selectController/getArea.html", dataid: "ID",defaultText: "<option value=''>请选择</option>",
            func: function () {
                $("#area3").HNSelect({
                    parent_selector: "#area2", url: "${pageContext.request.contextPath}/selectController/getArea.html", dataid: "ID", defaultText: "<option value=''>请选择</option>",
                });
            }
        });
        
        
    });
    
    
    function save() {
    	var rowIds = $("#gridlist").jqGrid("getDataIDs")||[];
		if (rowIds.length <= 0) {
			$.HN.message.alert("没有数据！", "消息", "warn");
			return;
		}
		var list = [];
		for (var i=0; i<rowIds.length; i++) {
			rowId = rowIds[i];
			var rowdata = $("#gridlist").jqGrid("getRowData",rowId);
			var maxDelnumBase = $.trim($("#base"+rowId).val());
			if(maxDelnumBase == null || maxDelnumBase == ""){
				$.alert("请输入基层医疗机构配送数！","warn");
				return;
			}
			if(!/^[1-9]{1}[0-9]?$/.test(maxDelnumBase)){
				$.alert("基层医疗机构配送数必须为不超过两位的正整数！","warn");
				return;
			}
			var maxDelnumCounty = $.trim($("#county"+rowId).val());
			if(maxDelnumCounty == null || maxDelnumCounty == ""){
				$.alert("请输入县级及县以上医疗机构配送数！","warn");
				return;
			}
			if(!/^[1-9]{1}[0-9]?$/.test(maxDelnumCounty)){
				$.alert("县级及县以上医疗机构配送数必须为不超过两位的正整数！","warn");
				return;
			}
			list.push({"areaId":rowdata.area_id,"areaName":rowdata.area_name,"arFullname":rowdata.ar_fullname,"maxDelnumBase":rowdata.max_delnum_base,"maxDelnumCounty":rowdata.max_delnum_county});
		}
		$.HN.message.confirm("确定保存吗？", "提示信息", "确定").on(function(bool) {
			if (bool) {
		       	$.ajax({
					type:"POST",
					url:"${ctx}/purConfig/setDelNum.html",
					data:{"array":JSON.stringify(list)},
					dataType:"json",
					success:function(result){
						if (result.success) {
							search();
							$.alert(result.msg||"操作成功！", "");
						} else {
		    				$.alert(result.msg||"操作失败！", "error");
		    			}
					},
					error:function() {
						top.window.document.location = "${ctx}/login.html";
					}
				});
			}
		});
	}
    </script>
</body>
</html>